/**
 * Copyright 2014,Peak Tai 台俊峰(taijunfeng_it@sina.com).
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * 		http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.cenluan.notification;

import java.util.Date;

import com.cenluan.kit.UUIDKit;
import com.cenluan.user.User;
import com.jfinal.plugin.activerecord.Model;

/**
 * 通知
 * 
 * @author peak
 * 
 */
public class Notification extends Model<Notification> {

	private static final long serialVersionUID = 1L;

	public static final Notification dao = new Notification();

	/**
	 * 获取关联用户
	 * 
	 * @return
	 */
	public User getUser() {
		return User.dao.findById(getStr("uerId"));
	}

	/**
	 * 保存通知
	 * 
	 * @param userId
	 * @param content
	 * @return
	 */
	public static boolean save(String userId, String content) {
		User.dao.findById(userId).clearNewCache();
		Notification notification = new Notification();
		notification.set("id", UUIDKit.generateUUID());
		notification.set("userId", userId);
		notification.set("content", content);
		notification.set("createTime", new Date());
		notification.set("read", false);
		return notification.save();
	}

}
